package com.example.controller;

import com.example.pojo.CusDevPlan;
import com.example.pojo.SaleChance;
import com.example.service.ICusDevPlanService;
import com.example.service.ISaleChanceService;
import com.example.util.BaseController;
import com.example.util.CookieUtil;
import com.example.vo.ResultVo;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *              客户开发计划
 * @author wsl
 * @since 2022-04-13
 */
@RestController
@RequestMapping("/cusDevPlan")
@Api(tags = "",value = "")
@CrossOrigin(allowCredentials = "true")
public class CusDevPlanController extends BaseController {
    @Autowired
    private ICusDevPlanService cusDevPlanService;

    @Autowired
    private ISaleChanceService saleChanceService;
    /**
     * 分页
     */
    @GetMapping("/pager")
    @ApiOperation(value = "获得客户开发计划分页信息")
    public PageInfo<CusDevPlan> displayPager(@RequestParam(defaultValue = "1")Integer pageNum,
                                             @RequestParam(defaultValue = "5")Integer pageSize){
        return cusDevPlanService.electByPager(pageNum,pageSize);
    }

    /**
     * 查询所有
     */
    @GetMapping("")
    public List<CusDevPlan> displayCusDevPlanInfo(){
        return cusDevPlanService.selectAll();
    }

    /**
     * 添加计划项
     */
    @ApiOperation(value = "添加计划项")
    @PostMapping("/add")
    public ResultVo addPlan(@RequestBody CusDevPlan cusDevPlan){
        return cusDevPlanService.addPlan(cusDevPlan);
    }
    /**
     * 开发成功
     */
    @ApiOperation(value = "开发成功")
    @PutMapping("/{id}")
    public ResultVo succeed(@PathVariable("id") Integer id){
        SaleChance saleChance = new SaleChance().setId(id).setDevResult(2);
        if (saleChanceService.updateById(saleChance)){
            return ResultVo.ok("开发成功！");
        }
        return ResultVo.error("修改失败！");
    }
    /**
     * 开发失败
     */
    @ApiOperation(value = "开发失败")
    @PutMapping("/sb/{id}")
    public ResultVo fail(@PathVariable("id") Integer id){
        SaleChance saleChance = new SaleChance().setId(id).setDevResult(3);
        if (saleChanceService.updateById(saleChance)){
            return ResultVo.ok("开发失败！");
        }
        return ResultVo.error("错误！");
    }
    /**
     * 执行成功
     */
    @ApiOperation(value = "执行成功")
    @PutMapping("/zx/{id}")
    public ResultVo execute(@PathVariable("id") Integer id){
        CusDevPlan cusDevPlan = new CusDevPlan().setId(id).setExeAffect("执行成功");
        if (cusDevPlanService.updateById(cusDevPlan)){
            return ResultVo.ok("执行成功！");
        }
        return ResultVo.error("错误！");
    }
    /**
     * 执行失败
     */
    @ApiOperation(value = "执行成功")
    @PutMapping("/execute/{id}")
    public ResultVo executeFail(@PathVariable("id") Integer id){
        CusDevPlan cusDevPlan = new CusDevPlan().setId(id).setExeAffect("执行失败");
        if (cusDevPlanService.updateById(cusDevPlan)){
            return ResultVo.ok("执行成功！");
        }
        return ResultVo.error("错误！");
    }
}
